package cn.hou.java.designpattern._15mediator;

//中介类 (模拟媒婆)
public class Mediator {
	//引用需要交互的类
	private Man man;
	private Woman woman;
	//中介机构来对两个人进行匹配      :需要匹配的对象
	public void getMatching(Person person){
		if(person instanceof Man)this.setMan((Man) person);
		if(person instanceof Woman)this.setWoman((Woman) person);
		//排除同性之间匹配,如果传的是同性,则两个引用中必然有一个为空,会导致空指针异常
		if(man==null || woman==null){
			System.out.println("抱歉,同性之间无法匹配");
		}else{
			if(man.getCondition()==woman.getCondition()){
				System.out.println(man.getName()+"和"+woman.getName()+"真是绝配");
				//清空引用,以便下次继续匹配
				this.man=null;
				this.woman=null;
			}else{
				System.out.println(man.getName()+"和"+woman.getName()+"不相配");
				this.man=null;
				this.woman=null;
			}
		}
	}
	//只提供set方法即可
	public void setMan(Man man) {
		this.man = man;
	}
	public void setWoman(Woman woman) {
		this.woman = woman;
	}
}
